package com.test37_反射应用;

import com.test37_反射应用.util.ObjectInstanceFactory;
import com.test37_反射应用.vo.Emp;
import org.junit.Test;

/**
 * 属性自动赋值
 */
public class YootkDemo_02 {
    // 假如这个数据信息是由服务器端返回的Emp对象的属性内容
    public static final String ECHO_DATA = "ename:小李老师|job:沐言讲师";
    public static final String ECHO_DATA2 = "empno:7886|ename:小李老师|job:沐言讲师|salary:5000.05|hiredate:2020-09-19 09:15:27";

    /**
     * 单级属性赋值
     */
    @Test
    public void test1() throws Exception {
        Emp emp = ObjectInstanceFactory.create(Emp.class, ECHO_DATA);   // 避免向下转型
        System.out.println(emp);
    }

    /**
     * 属性类型转换
     */
    @Test
    public void test2() throws Exception {
        Emp emp = ObjectInstanceFactory.create(Emp.class, ECHO_DATA2);  // 避免向下转型
        System.out.println(emp);
    }
}
